package com.cuit.freshmanMS.controller;


import com.cuit.freshmanMS.domain.Academy;
import com.cuit.freshmanMS.query.AcademyQuery;
import com.cuit.freshmanMS.service.AcademyService;
import com.cuit.freshmanMS.util.result.CommonResult;
import com.cuit.freshmanMS.util.result.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
public class AcademyController {
    @Autowired
    private AcademyService academyService;

    @GetMapping("/academy")
    public List<Academy> loadAll(){
        List<Academy> academies = academyService.loadAll();
        return academies;
    }

    @PostMapping("/academy")
    public CommonResult addAca(@RequestBody Academy academy){
        return academyService.addAca(academy);
    }

    @PutMapping("/academy")
    public CommonResult updateAca(@RequestBody Academy academy){
        return academyService.updateAca(academy);
    }

    @DeleteMapping("/academy/{ano}")
    public CommonResult deleteAca(@PathVariable("ano") Integer ano){
        return academyService.deleteAcaByAno(ano);
    }

    @RequestMapping("/academy/batchDelete")
    public CommonResult batchDelete(@RequestBody List<Integer> anos){
        return academyService.batchDelete(anos);
    }

    @PostMapping("/academy/selectAll")
    PageResult<Academy> selectAll(@RequestBody AcademyQuery academyQuery) {
        return academyService.selectAll(academyQuery);
    }

    @GetMapping("/academy/{ano}")
    public CommonResult<Academy> getAcaByAno(@PathVariable("ano") Integer ano){
        return academyService.getAcaByAno(ano);
    }
}
